import { createRouter, createWebHistory } from 'vue-router'
import Layout from '@/layout/index.vue'

const mainRoute = [
  {
    path: '/',
    redirect: 'login'
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import(/* webpackChunkName: "login" */ '@/views/Login/index.vue')
  },
]

export const asyncRoute = [
  {
    path: '/main',
    component: Layout,
    redirect: '/main/index',
    name: 'Main',
    hidden: false,
    meta: {
      title: '平台概览'
    },
    children: [
      {
        path: 'index',
        component: () => import(/* webpackChunkName: "home" */ '@/views/Main/index.vue'),
        name: 'main',
        hidden: false,
        meta: {
          title: '平台概览'
        }
      },
      {
        path: 'test',
        component: () => import(/* webpackChunkName: "home" */ '@/views/Main/index.vue'),
        name: 'test',
        hidden: true,
        meta: {
          title: '测试'
        }
      }
    ]
  },
  {
    path: '/table',
    component: Layout,
    redirect: '/table/index',
    name: 'Table',
    hidden: false,
    meta: {
      title: '表格组件'
    },
    children: [
      {
        path: 'index',
        component: () => import(/* webpackChunkName: "home" */ '@/views/Table/index.vue'),
        name: 'Table',
        hidden: false,
        meta: {
          title: '表格组件'
        }
      },
    ]
  },
  {
    path: '/directive',
    component: Layout,
    redirect: '/directive/index',
    name: 'Directive',
    hidden: false,
    meta: {
      title: '自定义指令'
    },
    children: [
      {
        path: 'index',
        component: () => import(/* webpackChunkName: "home" */ '@/views/Directive/index.vue'),
        name: 'Directive',
        hidden: false,
        meta: {
          title: '自定义指令'
        }
      },
    ]
  }
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [...mainRoute, ...asyncRoute]
})

export default router